package com.qingke.memo.factory;

import java.util.HashMap;
import java.util.Map;

import com.qingke.memo.command.Command;
import com.qingke.memo.command.system.AlterCustomTag;
import com.qingke.memo.command.system.AlterMemo;
import com.qingke.memo.command.system.CreateCustomTag;
import com.qingke.memo.command.system.CreateMemo;
import com.qingke.memo.command.system.DeleteCustomTag;
import com.qingke.memo.command.system.DeleteMemo;
import com.qingke.memo.command.system.GoToMemo;
import com.qingke.memo.command.system.HelpSystem;
import com.qingke.memo.command.system.SelectMemoByContentKey;
import com.qingke.memo.command.system.SelectMemoByCreateTime;
import com.qingke.memo.command.system.SelectMemoByCustomTag;
import com.qingke.memo.command.system.SelectMemoById;
import com.qingke.memo.command.system.SelectMemoByTitle;

public class SystemCommandFactory extends CommandFactory{
	private static Map<CommandCode,Class<? extends Command>> systemMap=new HashMap<>();
	
	static{
		systemMap.put(CommandCode.ALTERCUSTOMTAG, AlterCustomTag.class);
		systemMap.put(CommandCode.ALTERMEMO, AlterMemo.class);
		systemMap.put(CommandCode.CREATECUSTOMTAG, CreateCustomTag.class);
		systemMap.put(CommandCode.CREATEMEMO, CreateMemo.class);
		systemMap.put(CommandCode.DELETECUSTOMTAG, DeleteCustomTag.class);
		systemMap.put(CommandCode.DELETEMEMO, DeleteMemo.class);
		systemMap.put(CommandCode.CONTENTKEY, SelectMemoByContentKey.class);
		systemMap.put(CommandCode.CREATETIME, SelectMemoByCreateTime.class);
		systemMap.put(CommandCode.CUSTOMTAG, SelectMemoByCustomTag.class);
		systemMap.put(CommandCode.ID, SelectMemoById.class);
		systemMap.put(CommandCode.TITLE, SelectMemoByTitle.class);
		systemMap.put(CommandCode.HELP, HelpSystem.class);
		systemMap.put(CommandCode.GOTOMEMO, GoToMemo.class);
	}
	
	@Override
	public Command buildCommand(CommandCode cmdCode) {
		Class<? extends Command> commandClass=systemMap.get(cmdCode);
		
		if(commandClass==null)
			return null;
		
		Command command=null;
		try {
			command = commandClass.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return command;
	}

}
